import Mock from 'mockjs'
/**
 * 模拟 GET 请求 '/mock/api/v1/list' 资源
 * 
 */
Mock.mock(/\/mock\/coupon.*/, 'post', (options: any) => {
  const body = JSON.parse(options.body)
  let num = 32 - (body.page - 1) * 5
  num = num > 5 ? 5 : num
  const data = Mock.mock({
    [`list|${num}`]: [{
      check: false,
      id: '@guid',
      'couponname|1': ['10元优惠券', '20元优惠券', '30元优惠券', '40元优惠券', '50元优惠券',],
      'scope|1': ['男士餐', '女士餐', '工作餐',],
      'condition|1': ['满50可用', '满100可用', '满80可用', '满200可用',],
      'sum|10-99': 0,
      'start|1': ['是', '是', '是', '否'],
      'ndoseame|50-200': 100,
      startTime: '@DATETIME("yyyy-MM-dd HH:mm:ss")',
      rule: '@ctitle(30,50)',
      //   image: '@image(375x150,@color)',

    }],
    total: 32,
    pageSize: 5,
  })
  if (body.mes) {
    let namelist =['10元优惠券', '20元优惠券', '30元优惠券', '40元优惠券', '50元优惠券',]
    // @ts-ignore
    namelist = namelist.filter(item=>{
      return  item.includes(body.mes)
    })
   
    // @ts-ignore
    data.list = data.list.map(item=>{
      const num = Math.floor(Math.random()*namelist.length)
      item.couponname =  namelist[num]
      return item
    })
    data.total = Math.ceil(data.total*namelist.length/5)
  }

  return {
    data,
    code: 200,
    message: '请求优惠券数据成功',
  }
})

Mock.mock(/\/mock\/pushcoupon.*/, 'post', (options: any) => {
  const data = Mock.mock({
    info: JSON.parse(options.body),
    message: '添加优惠券成功',
  })
  return {
    data,
    code: 200,
    message: '添加优惠券成功',
  }
})
